<template>
	<view class="container">
		<view class="bgc">
			<view class="yue">
				<text>我的余额 (元)</text>
				<text class="money">{{userInfo.money}}</text>
			</view>

			<view class="btn">
			<!-- 	<view class="drawal" @click="drawal">
					<image src="/static/img/money/drawal.png" mode="widthFix"></image>
					<text>押金退还</text>
				</view> -->
				<view class="reCharge" @click="reCharge">
					<image src="/static/img/money/reCharge.png" mode="widthFix"></image>
					<text>充值</text>
				</view>
			</view>
		</view>

		<view class="tit">
			<text>明细</text>
		</view>

		<scroll-view scroll-y class="list" v-if="list.length != 0" @scrolltolower="loadMore">
			<view class="list_item" v-for="(item,index) in list" :key="index">
				<view class="item_l">
					<text>{{item.memo}}</text>
					<text class="time">{{item.createtime_date}}</text>
				</view>
				<view class="item_r">
					{{item.money_type}} {{item.money}}
				</view>
			</view>
		</scroll-view>
		<view class="list" v-else>
			<view class="empty">
				暂无明细
			</view>
		</view>


	</view>
</template>

<script>
	import {
		capital,
		getUserInfo
	} from '../../../api/api.js'
	export default {
		data() {
			return {
				userInfo: {},
				list: [],
				total: 0,
				last_page: 1,
				current_page: 1,
				per_page: 30
			}
		},
		onLoad() {},
		onShow() {
			this.userInfo = uni.getStorageSync('user')
			console.log(uni.getStorageSync('user'))
			this.getInfo()
			this.current_page = 1
			this.jilu()
		},
		methods: {
			reCharge() {
				uni.navigateTo({
					url: '/pages/user/detail/reChange'
				})
			},
			drawal() {
				uni.navigateTo({
					url: '/pages/user/detail/drawal'
				})
			},
			getInfo() {
				getUserInfo().then(res => {
					console.log(res)
					this.userInfo = res.data
					uni.setStorageSync('user', res.data)
				})
			},
			jilu(loadMore) {
				capital({
					limit: this.per_page,
					page: this.current_page
				}).then(res => {
					if (loadMore) {
						console.log(loadMore)
						for (let i = 0; i < res.data.data.length; i++) {
							this.list.push(res.data.data[i])
						}
					} else {
						this.list = res.data.data
					}
					this.total = res.data.total
					this.last_page = res.data.last_page
					this.current_page = res.data.current_page
				})
			},
			loadMore(e) {
				// console.log(e)
				if (this.current_page < this.last_page) {
					this.current_page += 1
					this.jilu('loadMore')
				}
			}
		},
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		height: 100%;
		background-color: #f6f6f6;
	}

	.bgc {
		width: 100%;
		height: 240upx;
		background-color: #25a0e6;
		color: #FFFFFF;
		padding-top: 60upx;

		.yue {
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			font-size: 24upx;

			.money {
				margin-top: 10upx;
				font-size: 70upx;
			}
		}

		.btn {
			width: 70%;
			margin: 20upx auto;
			display: flex;
			justify-content: space-between;

			.drawal,
			.reCharge {
				width: 200upx;
				margin: auto;
				height: 60upx;
				border: 1upx solid #FFFFFF;
				border-radius: 30upx;
				display: flex;
				justify-content: center;
				align-items: center;
				line-height: 1;
				font-size: 28upx;

				image {
					margin-right: 15upx;

				}
			}

			.reCharge {
				background-color: #fff;
				border: none;
				color: #25a0e6;
			}

			image {
				width: 30upx;
				height: 28upx;
			}
		}

	}

	.tit {
		height: 60upx;
		line-height: 60upx;
		color: #999999;
		margin-left: 30upx;
	}

	.list {
		width: 100%;
		height: calc(100% - 380upx);
		background-color: #FFFFFF;
		margin-top: 10upx;

		.list_item {
			width: calc(100% - 60upx);
			height: 100upx;
			margin: 0 auto;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 1upx solid #f7f7f7;

			.item_l {
				height: 80%;
				display: flex;
				font-size: 28upx;
				flex-direction: column;
				justify-content: space-around;

				.time {
					color: #999999;
					font-size: 24upx;
				}
			}

			.item_r {
				color: #25a0e6;
				font-size: 36upx;
			}

		}

		.empty {
			width: calc(100% - 60upx);
			height: 100upx;
			text-align: center;
			line-height: 100upx;
		}
	}
</style>
